package main

import (
	"fmt"
	"net"
	"strconv"
)

func Write(conn net.Conn, txt string) {
	conn.Write([]byte(fmt.Sprintf("%05d", len(txt))))
	conn.Write([]byte(txt))
}

func Read(conn net.Conn) string {
	lengthByte := make([]byte, 5)
	conn.Read(lengthByte)
	length, _ := strconv.Atoi(string(lengthByte))
	lengthctx := make([]byte, length)
	conn.Read(lengthctx)
	return string(lengthctx)
}

func main() {
	conn, err := net.Dial("tcp", "127.0.0.1:8989")
	if err != nil {
		fmt.Println(err)
		return
	}

	Write(conn, "你好")

	conn.Close()

}
